//
//  RealNameAuthViewController.m
//  PPDL
//
//  Created by 王洋 on 2019/7/24.
//  Copyright © 2019 王洋. All rights reserved.
//

//#import "TZImagePickerController.h"
#import "RealNameAuthViewController.h"

@interface RealNameAuthViewController ()

@property (weak, nonatomic) IBOutlet UITextField *IDCardName;

@property (weak, nonatomic) IBOutlet UITextField *IDCardCode;

@property (weak, nonatomic) IBOutlet UIButton *agreeBtn;

@property (assign, nonatomic) BOOL isAgree;

@end

@implementation RealNameAuthViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];
}

- (void)initView {
    
    self.title = @"实名认证";
    self.isAgree = NO;
}

- (void)request_RealNameAuth{
    
    NSDictionary *dic = @{}.mutableCopy;
    
    NSString *realName = self.IDCardName.text;
    [dic setValue:realName forKey:@"realname"];
    [dic setValue:self.IDCardCode.text forKey:@"idcard"];
    
    
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,TT_MEMBER_REALNAME_AUTH];
    
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        
        if ([data isKindOfClass:[NSDictionary class]]) {
            
            NSString * code = [data valueForKey:@"code"];
            if ([code isEqualToString:@"200"]) {

                [self.navigationController popToRootViewControllerAnimated:YES];
                [self alert:[data valueForKey:@"msg"]];

            } else {
                
                [self alert:[data valueForKey:@"msg"]];
            }
        } else {
            
        }
        
    } FailedBlock:^(NSError * _Nonnull error) {
        
    }];
    
}

//去网页
- (IBAction)goHtmlClick:(id)sender {
    
    PPWebViewController * webvc = [[PPWebViewController alloc] init];
    webvc.webUrl = [NSString stringWithFormat:@"%@%@",TT_Global_H5_Domain,TT_HTML_PRIVACY_POLICY];
    [self.navigationController pushViewController:webvc animated:YES];
}

//开始认证
- (IBAction)goRequest:(id)sender {
    
    if (self.IDCardName.text.length && self.IDCardCode.text.length) {
        
        if (self.isAgree) {
            
            [self request_RealNameAuth];
        } else {

            [self alert:@"请阅读并同意《用户协议与隐私政策》"];
        }
    } else {
        
        [self alert:@"姓名或身份证号不能为空"];
    }
}

- (IBAction)agreeOrNo:(id)sender {
    
    self.isAgree = !self.isAgree;
    
    [self.agreeBtn setImage:self.isAgree?[UIImage imageNamed:@"admire_bg"]:[UIImage imageNamed:@"empty_bg"] forState:UIControlStateNormal];
}


@end
